<template>
  <el-menu
    router
    :default-active="this.$route.path"
    class="el-menu-vertical-demo"
    @open="handleOpen"
    @close="handleClose"
    background-color="#545c64"
    text-color="#fff"
    active-text-color="#ffd04b"
    style="overflow:auto;"
    :unique-opened="true"
    :style="prop_headzHeight"
  >
    <menu-recursive :menupath="menuPath"></menu-recursive>
  </el-menu>
</template>

<script>
import menuRecursive from "./LeftMenuRecursive.vue";
import routes from "../router.js";
import LeftMenu from "../config/leftmenu.js";

export default {
  components: {
    menuRecursive
  },
  props: ["headzHeight"],
  data() {
    return {
      userAuth: [1, 2, 3, 5, 7],
      menuPath: []
    };
  },
  mounted() {
      /**
       * LeftMenu为所有菜单,令其与userAuth比对,渲染符合条件的菜单,放置于menuPath中(只判断一级菜单里的权限)
      */
    LeftMenu.forEach((v, k) => {
      var __result = this.userAuth.find(authNum => {
        return authNum === v.alevel.auth;
      });
      if (__result) {
        this.menuPath.push(v);
      }
    });
  },
  computed: {
    prop_headzHeight() {
      var _menuHeight =
        document.documentElement.clientHeight - this.headzHeight;
      return "height:" + _menuHeight + "px";
    }
  },

  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath, "开");
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath, "关");
    }
  }
};
</script>

<style scoped>
</style>
